package com.tencent.wxcloudrun.controller;

import com.alibaba.fastjson2.JSONObject;
import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.model.MyGoods;
import com.tencent.wxcloudrun.service.MyGoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/goods")
public class MyGoodsController {

    @Autowired
    private MyGoodsService goodsService;
    final Logger logger = LoggerFactory.getLogger(MyGoodsController.class);

    @PostMapping(value = "/list")
    ApiResponse getInfoList() {
//        logger.info("/api/count get request");
//        logger.info(param.toString());
        List<MyGoods> list= goodsService.findAll();
//        Integer count = 0;
//        if (counter.isPresent()) {
//            count = counter.get().getCount();
//        }

        return ApiResponse.ok(list);
    }

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

//        list.stream().filter((a)->{
//            return true;
//        }).forEach((a)->{
//            System.out.println(a);
//        });

        list.forEach((a)->{
            System.out.println(a);
        });

        Collections.sort(list,(a,b)->{
            return (int)a-(int)b;
        });

        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> collect = integers.stream().filter(a ->a >= 5).collect(Collectors.toList());
        System.out.println(collect);

        String aa = "abc";
        Optional.ofNullable("aabbcc").map(String::toUpperCase).ifPresent(System.out::println);
        Optional.ofNullable("null").map(String::toUpperCase).ifPresent(System.out::println);
        Optional.ofNullable("").ifPresent(System.out::println);
        System.out.println("end");

        JSONObject jsonObject = JSONObject.parseObject("{\"result\":{\"code\":\"0\"}}");

        Optional.ofNullable(jsonObject.getJSONObject("result").getString("code1")).ifPresent((a)-> {
//            String bb= a.getString("code");
            System.out.println(123);
        });
    }
}
